<?php namespace Phpcmf\Controllers;

class Buyjiugetu extends \Phpcmf\Home\Mform {
	// 继承类初始化
	protected function _Extend_Init() {
	    // 初始化模块
	    $this->_module_init(APP_DIR);
	
	    // 判断表单是否操作
	    $this->form = $this->module['form']['son'];
	    if (!$this->form) {
	        $this->_msg(0, dr_lang('模块表单00【%s】不存在',\Phpcmf\Service::L('Router')->class));
	    }
	
	    // 支持附表存储
	    $this->is_data = 1;
	    // 模板前缀(避免混淆)
	    $this->tpl_name = $this->form['table'];
	    $this->tpl_prefix = 'mform_';
	
	    // 初始化数据表
	    $this->_init([
	        'table' => dr_module_table_prefix(APP_DIR).'_form_'.$this->form['table'],
	        'field' => $this->form['field'],
	        'show_field' => 'title'
	    ]);

	}


    public function index() {

        $id = (int)\Phpcmf\Service::L('Input')->get('id');
        if (!$id) {
            exit($this->_msg(0, dr_lang('id参数不完整')));
        } elseif (!$this->uid) {
            $this->_msg(0, dr_lang('登录之后才能购买'));
        }
		
		$dateid = \Phpcmf\Service::M()->table('1_'.MOD_DIR.'_form_son')->get($id);
		//dr_debug('文件名称', $dateid);
        if (!$dateid) {
            $this->_msg(0, dr_lang('帖子id不存在'));
        } elseif ($dateid['uid'] == $this->uid) {
            $this->_msg(0, dr_lang('不能购买自己的'));
        } elseif (\Phpcmf\Service::M('buyjiugetu', MOD_DIR)->is_buy($this->uid, $id)) {
			/*$tianshus = \Phpcmf\Service::M()->db->table('1_'.MOD_DIR.'_form_son')->where('id', $id)->get()->getRowArray();
			$tianshu = (int)$tianshus['yxsj'];
			if ($tianshu == 0) {
				$this->_msg(0, dr_lang('已经购买过，无需重复购买'));
			} else {
				
				
			}
			$daoqi = \Phpcmf\Service::M()->db->table('1_'.MOD_DIR.'_tupian_buy')->where('cid', $id)->where('uid', $this->uid)->get()->getRowArray();
			dr_debug('$daoqi', $daoqi);
			if ($daoqi['endtime'] < time()) {
				
			} else {
				$this->_msg(0, dr_lang('已经购买过，无需重复购买'));
			}*/
			$this->_msg(0, dr_lang('已经购买过，无需重复购买'));
				
			
        }
		$yue = dr_payform('my-'.MOD_DIR.'_buyjiugetu-'.$id);
		//dr_debug('文件名称', $yue);

        \Phpcmf\Service::V()->assign([
            'payform' => dr_payform('my-'.MOD_DIR.'_buyjiugetu-'.$id),
            'meta_title' => dr_lang('在线付款').SITE_SEOJOIN.SITE_NAME,
            'meta_keywords' => $this->get_cache('site', SITE_ID, 'config', 'SITE_KEYWORDS'),
            'meta_description' => $this->get_cache('site', SITE_ID, 'config', 'SITE_DESCRIPTION')
        ]);
        \Phpcmf\Service::V()->display('buyjiugetu.html');
    }
}
